/**
 * Creat by TanLei
 * Description:
 * User:86183
 * Date:2022-05-11
 * Time:18:38
 */
class Counter {
    public int count = 0;

//    synchronized public void increase(){
//        count++;
//    }
    public void increase(){
        synchronized (this){
            count++;
        }
    }
}
public class Demo15 {
    private static Counter counter = new Counter();

    public static void main(String[] args) {
        Thread thread1 = new Thread(()->{
           for(int i=0;i<50000;i++){
               counter.increase();
           }
        });

        Thread thread2 = new Thread(()->{
            for(int i=0;i<50000;i++){
                counter.increase();
            }
        });

        thread1.start();
        thread2.start();

        try {
            thread1.join();
            thread2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(counter.count);
    }
}
